<template>
  <el-container>
    <!-- 头部 -->
    <el-header style="height: 100px" class="home-header">
      <span>社团人员管理系统</span>
      <div class="user-info">
        <i>{{ userInfo.name }}</i>
        <i>是否是管理员：{{ userInfo.limits }}</i>
      </div>
      <el-button type="primary" class="logout" @click="logout">注销</el-button>
    </el-header>
    <!-- 页面主体区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="300px">
        <el-menu
          :default-active="$route.path"
          class="el-menu-vertical-demo"
          background-color="#5d6371"
          text-color="#eee"
          active-text-color="#1391E3"
          router
        >
          <!-- 一级菜单 -->
          <el-submenu :index="'/my'">
            <template slot="title">
              <span>个人信息展示</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item-group>
              <el-menu-item :index="'/myself/' + userInfo.id"
                >个人信息</el-menu-item
              >
            </el-menu-item-group>
          </el-submenu>

          <!-- 一级菜单 -->
          <el-submenu :index="'/manage'">
            <template slot="title">
              <span>权限管理</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item-group>
              <el-menu-item :index="'/common'">普通用户权限</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group>
              <el-menu-item :index="'/super'">超级用户权限</el-menu-item>
            </el-menu-item-group>
          </el-submenu>

          <el-submenu
            :index="'/show/' + item1.id"
            v-for="item1 in section"
            :key="item1.id"
          >
            <template slot="title">
              <span>{{ item1.name }}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item-group v-for="item2 in item1.children" :key="item2.id">
              <el-menu-item :index="'/show/' + item2.id">{{
                item2.name
              }}</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 主体区域 -->
      <el-main>
        <router-view></router-view>
        <!-- <show :post="post"></show> -->
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import show from "../components/show.vue";

export default {
  name: "home",
  data() {
    return {
      section: [],
      post: [],
      // userInfo: {
      //   name: "",
      //   age: "",
      //   birthday: "",
      //   sex: "",
      //   password: "",
      //   other: "",
      //   poid: "",
      //   limits: "",
      // },
      userInfo: {
        name: "",
        limits: "",
        id: null,
      },
    };
  },
  components: {
    show,
  },
  created() {
    this.getsection();
  },
  mounted() {
    this.getUserInfo();
  },
  methods: {
    // 注销
    logout() {
      window.sessionStorage.clear("token");
      window.localStorage.clear("limits");
      this.$router.push("/login");
    },
    // 请求部门数据
    getsection() {
      this.axios
        .get("/getsection")
        .then((response) => {
          this.section = response.data;
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // // 请求岗位数据
    // getpost() {
    //   this.axios
    //     .get("/getpost")
    //     .then((response) => {
    //       // console.log(response);
    //       this.post = response.data;
    //     })
    //     .catch((error) => {
    //       console.log(error);
    //     });
    // },

    getUserInfo() {
      this.userInfo.name = window.sessionStorage.getItem("name");
      this.userInfo.limits = window.localStorage.getItem("limits");
      this.userInfo.id = window.localStorage.getItem("id");
    },
    // 获得当前登录用户的所有信息
    // getUserInfo() {
    //   console.log("userInfo:" + this.$route.query.id);
    //   this.axios
    //     .get("/getuserinfo", {
    //       params: {
    //         id: this.$route.query.id,
    //       },
    //     })
    //     .then((response) => {
    //       console.log(response);
    //       this.userInfo = response.data[0];
    //     })
    //     .catch((error) => {
    //       console.log(error);
    //     });
    // },
  },
};
</script>


<style lang="less" scoped>
.el-container {
  height: 100%;
  .el-header {
    background-color: #5d6371;
    color: #eee;
    font-size: 30px;
    text-align: center;
    line-height: 100px;
  }
  .el-aside {
    background-color: #5d6371;
    .toggle_btn {
      background-color: pink;
      color: #fff;
      font-size: 10px;
      line-height: 24px;
      text-align: center;
      letter-spacing: 2px;
      cursor: pointer;
    }
    h5 {
      text-align: center;
      margin: 10px 0;
      color: #eee;
      font-family: 幼圆;
      font-size: 30px;
    }
    .el-menu {
      // 清楚border
      border: none;
    }
  }
  .el-main {
    background-color: #eee;
  }
}
.home-header {
  position: relative;
}
.logout {
  position: absolute;
  top: 30px;
  right: 50px;
}
.user-info {
  position: absolute;
  top: -30px;
  right: 50px;
  font-size: 15px;
}
</style>